<?php

/*
 * 协会推送接口
 * 商家推送
 */

namespace Association\Controller;

use Think\Controller;

class ServiceController extends Controller {

    //const IP = '192.168.0.115';
    //const IP = '210.51.17.16:80';

    public function __construct() {
        parent::__construct();
        /*$ip = getUserIP();
        if ($ip != self::IP) {   //只允许美协IP访问
            exit;
        }*/
        $this->service = D('Service','Logic');
    }

    public function getToken() {
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
        header("Cache-Control: no-cache, must-revalidate");
        header("Pramga: no-cache");
        $token = $this->service->createToken();
        exit($token);
    }

    public function pushShop() {
        if(strlen($_GET['qyqc_txt'])>0){
                $data = $_GET;
        }else{
                $data = $_POST;
        }
        if(strlen(trim($data['qyqc_txt']))<1){
            header("Location:http://www.bjmx.org/qyxxcj/tj.asp");
            exit;
        }
        unset($data['validatecode']);
        $data['IsAddManage'] = $data['isma'];
        unset($data['isma']);
        $data['IsSustain'] = $data['isw'];
        unset($data['isw']);
        unset($data['submit']);
        $data['RegisterTime'] = date('Y-m-d H;i:s',time());
        foreach($data as $k=>$v){
                $kk = substr($k,0,-4);
                $arr[$kk] = iconv('GB2312', 'UTF-8', $v);
        }
        $re = $this->service->getByName($arr['qyqc']);
        if($re['id']>0){
            header("Location:http://www.bjmx.org/qyxxcj/tj.asp");
            exit;
        }
        $id = $this->service->addData($arr);
        if($id>0){
            $re = 'SUCCESS';
        }else{
            $re = 'FAIL';
        }
        $f = fopen("./oo.txt",'a+');
        fputs($f, json_encode($_POST).$re."\r\n", 10240);
        fputs($f, json_encode($arr).$re."\r\n\r\n", 10240);
        header("Location:http://www.bjmx.org/qyxxcj/tj.asp");
    }

}
